const mongoose = require("mongoose");

// 消息模型
const MessageSchema = new mongoose.Schema({
  from: String,
  to: String,
  message: String,
  timestamp: { type: Date, default: Date.now },
});

const Message = mongoose.model("Message", MessageSchema);

// 连接关系模型
const UserJoinSchema = new mongoose.Schema({
  user1: String,
  user2: String,
  is: Boolean,
  lastmsg: String,
  to: String,
  isread: { type: Number, default: 0 },
  msgtime: { type: Date, default: Date.now },
  timestamp: { type: Date, default: Date.now },
});

const UserJoin = mongoose.model("UserJoin", UserJoinSchema);

// 用户列表模型
const UserListSchema = new mongoose.Schema({
  id: String,
  username: String,
  timestamp: { type: Date, default: Date.now },
});

const UserList = mongoose.model("UserList", UserListSchema);

// 聊天室模型
const chatRoomSchema = new mongoose.Schema({
  name: { type: String, required: true },
  creator: {
    type: String,
    required: true,
  },
  members: [{ type: String }],
});

const ChatRoom = mongoose.model("ChatRoom", chatRoomSchema);

module.exports = { Message, UserJoin, UserList, ChatRoom };
